{% extends "base.html" %}
{% block title %}首页{% endblock %}
{% load staticfiles %}
{% block content %}
    <div class="admin">
        <div class="listbiaoti" style="margin: 15px 15px 0px 17px; width: 98%; background-color: #ffffff">
            <ul> Android打包</ul>
            <dl style="float: right;"> 当前位置： 客户端打包 > <a href="#">Android打包</a></dl>
        </div>
        <div style="margin: 0px 15px 0px 17px; width: 98%; background-color: #ffffff; border-style: 1px solid; border-color:#909090;">
            <p style="margin: 0 0 0 10px; padding: 10px 0 0 10px; background-color: #ffffff">
                请输入邮箱地址：
                <input id= "email-input" type="text" style="border-radius: 5px; width: 20%; height:30px; font-size: 14px; padding: 2px 6px 3px; color: #333" placeholder="报告接收邮箱"></input>
            </p>
            <p style="margin: 0 0 0 10px;padding: 10px 0 0 10px; background-color: #ffffff">
                请选择编译版本：
                <select class="selectpicker" data-width="20%">
                    <option disabled selected = "selected">请选择想要查询的版本</option>
                    <option value="DEBUG">DEBUG 测试包</option>
                    <option value="RELEASE">RELEASE 提审包</option>
                </select>
            </p>
            <p style="margin: 0 0 0 10px;padding: 10px 0 0 10px; background-color: #ffffff">
                请输入代码分支：
                <input id="branch-input" type="text" style="border-radius: 5px; width: 20%; height:30px; font-size: 14px; padding: 2px 6px 3px; color: #333" placeholder="GIT对应分支名称"></input>
            </p>
            <button id="btn-build" class="btn btn-primary" style="margin: 15px 0 0 15px; width: 80px">编译</button>
        </div>
        <div class="container" style="margin: 0px 15px 0px 17px; width: 98%; background-color: #ffffff">
            <table class="table table-bordered col-lg-5" style="width: 100%; height: 100%; margin: 15px auto">
                <thead>
                <tr>
                    <th>编译号</th>
                    <th>编译时间</th>
                    <th>版本号</th>
                    <th>文件名</th>
                    <th>git分支</th>
                    <th>git-commit</th>
                    <th>编译版本</th>
                    <th>编译结果</th>
                    <th>查看log</th>
                    <th>二维码下载</th>
                    <th>操作</th>
                </thead>
                <tbody>
                    {% for build in buildlist %}
                        <tr>
                            <td>{{build.buildnumber}}</td>
                            <td>{{build.buildtime}}</td>
                            <td>{{build.versionnumber}}</td>
                            <td>{{build.filename}}</td>
                            <td>{{build.gitbranch}}</td>
                            <td>{{build.gitcommit}}</td>
                            <td>{{build.buildtype}}</td>
                            {% if build.buildresult == 'SUCCESS' %}
                                <td style='color: green'>{{build.buildresult}}</td>
                            {% elif build.buildresult == None %}
                                <td style='color: gray'>BUILDING</td>
                            {% else %}
                                <td style='color: red'>{{build.buildresult}}</td>
                            {% endif %}
                            <td><a href={{build.logpath}}>查看</a></td>
                            <td><img herght="100 px" width="100 px" src={{build.pngurl}} /></td>
                            <td><a href={{build.downloadpath}}>下载</a></td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
    <script language="JavaScript">
        $('#btn-build').click(function(){
            var data = {
                email: $("#email-input").val(),
                buildtype: $(".selectpicker").find("option:selected").val(),
                branch: $("#branch-input").val(),
            }
            console.log(data)
            $.ajax({  
                type : 'post',
                url : "/api/package_android_build/",
                contentType: "application/json",
                data: JSON.stringify(data),
                success : function(datas) {
                    let alldata = JSON.parse(datas)
                    myAlert(alldata.msg);
                },
                error: function () {
                    myAlert('Sorry，服务器可能开小差啦, 请重试!');
                }
            });
        });

    </script>

{% endblock %}